﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using DingApi.Models;
using System.Data;

using System.Web;
using Dingding.Helper;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

/*
 * 材料处置
 * 
 */
namespace DingApi.Controllers
{
    [RoutePrefix("api/Ym06sr")]
    public class Ym06srController : ApiController
    {


       

        /// <summary>
        /// /暂时不用；
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostYm06sr_Bill_inq")]
        public System.Data.DataSet PostYm06sr_Bill_inq([FromBody]  JObject obj)
        {
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");


            string MAT_NO = obj["MAT_NO"] == null ? "" : obj["MAT_NO"].ToString();
            string BILL_OF_LADING_NO = obj["BILL_OF_LADING_NO"] == null ? "" : obj["BILL_OF_LADING_NO"].ToString();

            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();




            string sql_temp = "";
          
            EI.EIInfo Block_TMM0001 = new EI.EIInfo();

             

            //根据【标签.批次号 + 提单子项.规格 物料主档表找材料及材料是否存在】
            //物料主档：PROD_CODE,SG_SIGN,MAT_SPEC_DESC,PACK_MODE_CODE + STOCK_NO + PROD_LOT_NO 基本唯一了
            sql_temp = " SELECT  ' ' PACK_MODE_NAME, t.*   FROM TMM0001 t "
                        + " WHERE  MAT_NO ='" + BILL_OF_LADING_NO + "'"
                        ;

            Block_TMM0001 = EF.Utility.ExecQuery(sql_temp);
            if (Block_TMM0001.Tables[0].Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "材料号[" + BILL_OF_LADING_NO + "]不存在！");
                return outBlock;
            }

            Block_TMM0001.Tables[0].TableName = "TMM0001";
            outBlock.Tables.Add(Block_TMM0001.Tables[0].Copy());
            


            outBlock.Tables["SYS"].Rows.Add(0, "");
            return outBlock;


        }


        

        /// <summary>
        /// 退库材料号扫描
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostYm06sr_mat_no_inq")]
        public System.Data.DataSet PostYm06sr_mat_no_inq([FromBody]  JObject obj)
        {
            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");
            

            string MAT_NO   = obj["MAT_NO"] == null ? "" : obj["MAT_NO"].ToString().Trim();
            string BILL_OF_LADING_NO = obj["BILL_OF_LADING_NO"] == null ? "" : obj["BILL_OF_LADING_NO"].ToString();

            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();
             

            string sql_temp = ""; 
            EI.EIInfo Block_TPMMM02N = new EI.EIInfo(); 
            EI.EIInfo Block_TMM0001 = new EI.EIInfo();

            if (MAT_NO == "")
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "请先扫描材料号！");
                return outBlock;
            }
            


            string sql_str0 = " select LOCATION_NO,MAT_NO, mat_wt,PROD_CODE,PROD_LOT_NO,qual_grade_code,Pack_Mode_Name ";
            sql_str0 += "       ,pack_mode_code,stock_no,mat_spec_desc";
            sql_str0 += "       ,SG_STD,SG_SIGN , ' ' BILL_OF_LADING_NO,ARCHIVE_FLAG  ";
            sql_str0 += "       ,to_char(to_date(OUT_TIME, 'yyyymmddhh24miss'), 'yyyy-mm-dd')  OUT_TIME,DUTY_MAKER  ";

            sql_str0 += "      ,STATUS,DPTMENT_CODE ,' ' QUAL_GRADE_NAME  from TPMMM02N                                                                                  ";
            sql_str0 += "       where mat_no = '" + MAT_NO + "' ";

            Block_TPMMM02N = EF.Utility.ExecQuery(sql_str0);
            if (Block_TPMMM02N.Tables[0].Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "标签材料[" + MAT_NO + "]不存在！");
                return outBlock;
            }

            ////验证该材料是否满足提单的要求；【仓库、包装方式、质量等级、规格、标准；】
            //if (Block_TPMMM02N.Tables[0].Rows[0]["STOCK_NO"].ToString() != STOCK_NO)
            //{
            //    outBlock.Tables["SYS"].Rows.Add(-1, "材料号[" + MAT_NO + "]不在库区[" + STOCK_NO + "]！");
            //    return outBlock;
            //}


            if (Block_TPMMM02N.Tables[0].Rows[0]["STATUS"].ToString() != "19")
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "材料号[" + MAT_NO + "]的状态不满足退库要求！");
                return outBlock;
            }


            string sql_str1 = "    select CODE_DESC_1_CONTENT from tep0002   where code_class = 'QMQK' "
                           + "   and code = '"+ Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_CODE"].ToString() + "'   ";
            //仓库代码转换
            EI.EIInfo outBlock_TEMP = EF.Utility.ExecQuery(sql_str1); //QUAL_GRADE_CODE

            if (outBlock_TEMP.Tables[0].Rows.Count>0)
            {
                Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_NAME"] = outBlock_TEMP.Tables[0].Rows[0]["CODE_DESC_1_CONTENT"];

            }




            //根据【标签.批次号 + 提单子项.规格 物料主档表找材料及材料是否存在】
            //物料主档：PROD_CODE,SG_SIGN,MAT_SPEC_DESC,PACK_MODE_CODE + STOCK_NO + PROD_LOT_NO 基本唯一了
            sql_temp = " SELECT  t.*   FROM TMM0001 t "
                        + " WHERE STOCK_NO= '" + Block_TPMMM02N.Tables[0].Rows[0]["STOCK_NO"].ToString() + "'  "
                        + " AND LOT_NO ='" + Block_TPMMM02N.Tables[0].Rows[0]["PROD_LOT_NO"].ToString() + "'"
                        + " AND MAT_NUM  >=1  AND MAT_WT >0 "
                        + " AND rownum = 1  "
                        + " AND PROD_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["PROD_CODE"].ToString() + "'"
                        + " AND SG_SIGN ='" + Block_TPMMM02N.Tables[0].Rows[0]["SG_SIGN"].ToString() + "'"
                        + " AND MAT_SPEC_DESC ='" + Block_TPMMM02N.Tables[0].Rows[0]["MAT_SPEC_DESC"].ToString().Replace("M", "").Replace("m", "") + "'"
                        + " AND PACK_MODE_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["PACK_MODE_CODE"].ToString() + "'"
                        + " AND QUAL_GRADE_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_CODE"].ToString() + "'"
                        ;

            Block_TMM0001 = EF.Utility.ExecQuery(sql_temp);
            if (Block_TMM0001.Tables[0].Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "物料主档找不到到满足签材料[" + MAT_NO + "]的材料！");
                return outBlock;
            }
            else
            {

                Block_TMM0001.Tables[0].Rows[0]["MAT_NUM"]          =   -1;
                Block_TMM0001.Tables[0].Rows[0]["MAT_WT"]           =   0 - double.Parse(Block_TPMMM02N.Tables[0].Rows[0]["MAT_WT"].ToString());
                Block_TMM0001.Tables[0].Rows[0]["DPTMENT_CODE"]     =   Block_TPMMM02N.Tables[0].Rows[0]["DPTMENT_CODE"];

                Block_TMM0001.Tables[0].Rows[0]["LOCATION_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["LOCATION_NO"];

                //图片数量
                if (!(Block_TMM0001.Tables[0].Columns.Contains("PACK_MODE_NAME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("PACK_MODE_NAME");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("OUT_TIME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("OUT_TIME");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("DUTY_MAKER")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("DUTY_MAKER");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("QUAL_GRADE_NAME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("QUAL_GRADE_NAME");
                }

                Block_TMM0001.Tables[0].Rows[0]["PONO_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["MAT_NO"];

                Block_TMM0001.Tables[0].Rows[0]["PACK_MODE_NAME"] = Block_TPMMM02N.Tables[0].Rows[0]["PACK_MODE_NAME"];
                Block_TMM0001.Tables[0].Rows[0]["OUT_TIME"] = Block_TPMMM02N.Tables[0].Rows[0]["OUT_TIME"];
                Block_TMM0001.Tables[0].Rows[0]["DUTY_MAKER"] = Block_TPMMM02N.Tables[0].Rows[0]["DUTY_MAKER"];
                Block_TMM0001.Tables[0].Rows[0]["QUAL_GRADE_NAME"] = Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_NAME"];




                








            }


            Block_TMM0001.Tables[0].TableName = "Table0";
            outBlock.Tables.Add(Block_TMM0001.Tables[0].Copy());
              
            outBlock.Tables["SYS"].Rows.Add(0, "");
            return outBlock;

        }




        /// <summary>
        /// 退库入库材料号扫描
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        [Route("PostYm06sr_mat_no_inq2")]
        public System.Data.DataSet PostYm06sr_mat_no_inq2([FromBody]  JObject obj)
        {
            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");


            string MAT_NO = obj["MAT_NO"] == null ? "" : obj["MAT_NO"].ToString().Trim();
            string BILL_OF_LADING_NO = obj["BILL_OF_LADING_NO"] == null ? "" : obj["BILL_OF_LADING_NO"].ToString();

            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();


            string sql_temp = "";
            EI.EIInfo Block_TPMMM02N = new EI.EIInfo();
            EI.EIInfo Block_TMM0001 = new EI.EIInfo();

            if (MAT_NO == "")
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "请先扫描材料号！");
                return outBlock;
            }



            string sql_str0 = " select *  from TPMMM02N                                                                                  ";
            sql_str0 += "       where mat_no = '" + MAT_NO + "' ";

            Block_TPMMM02N = EF.Utility.ExecQuery(sql_str0);
            if (Block_TPMMM02N.Tables[0].Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "标签材料[" + MAT_NO + "]不存在！");
                return outBlock;
            }

            Block_TPMMM02N.Tables[0].Rows[0]["PONO_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["MAT_NO"].ToString();

            Block_TPMMM02N.Tables[0].Rows[0]["LOT_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["PROD_LOT_NO"].ToString();
            Block_TPMMM02N.Tables[0].Rows[0]["RAW_SORT"] = " ";

            


            ////验证该材料是否满足提单的要求；【仓库、包装方式、质量等级、规格、标准；】
            //if (Block_TPMMM02N.Tables[0].Rows[0]["STOCK_NO"].ToString() != STOCK_NO)
            //{
            //    outBlock.Tables["SYS"].Rows.Add(-1, "材料号[" + MAT_NO + "]不在库区[" + STOCK_NO + "]！");
            //    return outBlock;
            //}


            if (Block_TPMMM02N.Tables[0].Rows[0]["STATUS"].ToString() != "11")
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "材料号[" + MAT_NO + "]的状态不满足生存退库入库要求要求！");
                return outBlock;
            }


            /*
            string sql_str1 = "    select CODE_DESC_1_CONTENT from tep0002   where code_class = 'QMQK' "
                           + "   and code = '" + Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_CODE"].ToString() + "'   ";
            //仓库代码转换
            EI.EIInfo outBlock_TEMP = EF.Utility.ExecQuery(sql_str1); //QUAL_GRADE_CODE

            if (outBlock_TEMP.Tables[0].Rows.Count > 0)
            {
                Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_NAME"] = outBlock_TEMP.Tables[0].Rows[0]["CODE_DESC_1_CONTENT"];
            }

           


            //根据【标签.批次号 + 提单子项.规格 物料主档表找材料及材料是否存在】
            //物料主档：PROD_CODE,SG_SIGN,MAT_SPEC_DESC,PACK_MODE_CODE + STOCK_NO + PROD_LOT_NO 基本唯一了
            sql_temp = " SELECT  t.*   FROM TMM0001 t "
                        + " WHERE STOCK_NO= '" + Block_TPMMM02N.Tables[0].Rows[0]["STOCK_NO"].ToString() + "'  "
                        + " AND LOT_NO ='" + Block_TPMMM02N.Tables[0].Rows[0]["PROD_LOT_NO"].ToString() + "'"
                        + " AND MAT_NUM  >=1  AND MAT_WT >0 "
                        + " AND rownum = 1  "
                        + " AND PROD_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["PROD_CODE"].ToString() + "'"
                        + " AND SG_SIGN ='" + Block_TPMMM02N.Tables[0].Rows[0]["SG_SIGN"].ToString() + "'"
                        + " AND MAT_SPEC_DESC ='" + Block_TPMMM02N.Tables[0].Rows[0]["MAT_SPEC_DESC"].ToString().Replace("M", "").Replace("m", "") + "'"
                        + " AND PACK_MODE_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["PACK_MODE_CODE"].ToString() + "'"
                        + " AND QUAL_GRADE_CODE ='" + Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_CODE"].ToString() + "'"
                        ;

            Block_TMM0001 = EF.Utility.ExecQuery(sql_temp);
            if (Block_TMM0001.Tables[0].Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "物料主档找不到到满足签材料[" + MAT_NO + "]的材料！");
                return outBlock;
            }
            else
            {

                Block_TMM0001.Tables[0].Rows[0]["MAT_NUM"] = -1;
                Block_TMM0001.Tables[0].Rows[0]["MAT_WT"] = 0 - double.Parse(Block_TPMMM02N.Tables[0].Rows[0]["MAT_WT"].ToString());
                Block_TMM0001.Tables[0].Rows[0]["DPTMENT_CODE"] = Block_TPMMM02N.Tables[0].Rows[0]["DPTMENT_CODE"];

                Block_TMM0001.Tables[0].Rows[0]["LOCATION_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["LOCATION_NO"];

                //图片数量
                if (!(Block_TMM0001.Tables[0].Columns.Contains("PACK_MODE_NAME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("PACK_MODE_NAME");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("OUT_TIME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("OUT_TIME");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("DUTY_MAKER")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("DUTY_MAKER");
                }
                if (!(Block_TMM0001.Tables[0].Columns.Contains("QUAL_GRADE_NAME")))
                {
                    Block_TMM0001.Tables[0].Columns.Add("QUAL_GRADE_NAME");
                }



                Block_TMM0001.Tables[0].Rows[0]["PONO_NO"] = Block_TPMMM02N.Tables[0].Rows[0]["MAT_NO"];
                Block_TMM0001.Tables[0].Rows[0]["PACK_MODE_NAME"] = Block_TPMMM02N.Tables[0].Rows[0]["PACK_MODE_NAME"];
                Block_TMM0001.Tables[0].Rows[0]["OUT_TIME"] = Block_TPMMM02N.Tables[0].Rows[0]["OUT_TIME"];
                Block_TMM0001.Tables[0].Rows[0]["DUTY_MAKER"] = Block_TPMMM02N.Tables[0].Rows[0]["DUTY_MAKER"];
                Block_TMM0001.Tables[0].Rows[0]["QUAL_GRADE_NAME"] = Block_TPMMM02N.Tables[0].Rows[0]["QUAL_GRADE_NAME"];

                



            }
              Block_TMM0001.Tables[0].TableName = "Table0";
            outBlock.Tables.Add(Block_TMM0001.Tables[0].Copy());

            */

            if (!(Block_TPMMM02N.Tables[0].Columns.Contains("QUAL_GRADE_NAME")))
            {
                Block_TPMMM02N.Tables[0].Columns.Add("QUAL_GRADE_NAME");
            }



            Block_TPMMM02N.Tables[0].TableName = "Table0";
            outBlock.Tables.Add(Block_TPMMM02N.Tables[0].Copy());


            outBlock.Tables["SYS"].Rows.Add(0, "");
            return outBlock;

        }




        //画面初始化【主要是各类小代码，类似之前画面的初始化参数】，暂时未用；
        //[HttpPost]
        //[Route("PostYm06sr_Load")]
        //public System.Data.DataSet PostYm06sr_Load([FromBody]  JObject obj)
        //{
        //    //系统信息；
        //    EI.EIInfo outBlock = new EI.EIInfo();
        //    outBlock.Tables.Add("SYS");
        //    outBlock.Tables["SYS"].Columns.Add("FLAG");
        //    outBlock.Tables["SYS"].Columns.Add("MSG");


        //    outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, outBlock.sys_info.msg);
        //    return outBlock;


        //}



        [HttpPost]
        [Route("PostYm06sr_save")]
        public System.Data.DataSet PostYm06sr_save([FromBody]  JObject obj)
        {

            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");


            string REMARK = obj["REMARK"] == null ? " " : obj["REMARK"].ToString();
            string APPLY_TIME = obj["OUT_TIME"] == null ? "" : obj["OUT_TIME"].ToString();


            string USERID = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();
            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();
            string PRO_TYPE = obj["PRO_TYPE"] == null ? " " : obj["PRO_TYPE"].ToString();


            DataTable table_rec_out = JsonConvert.DeserializeObject<DataTable>(obj["table_rec"].ToString());


            if (table_rec_out.Rows.Count < 1)
            {
                outBlock.Tables["SYS"].Rows.Add(-1, "缺少退库明细数据！");
                return outBlock;
            }


            EI.EIInfo inBlock = new EI.EIInfo();


            string sql_temp = " SELECT  t.*   FROM TMM0034 t  "
                      + " WHERE  1=2 "
                      ;

            inBlock = EF.Utility.ExecQuery(sql_temp);
            inBlock.Tables[0].Rows.Add();

            inBlock.Tables[0].Rows[0]["COMPANY_CODE"] = "NM";
            inBlock.Tables[0].Rows[0]["BRANCH_CODE"] = "N";
            inBlock.Tables[0].Rows[0]["BILL_STATUS"] = "10";
            inBlock.Tables[0].Rows[0]["MOVE_STOCK_TYPE"] = "SR";


            inBlock.Tables[0].Rows[0]["REC_CREATE_TIME"] = DateTime.Now.ToString("yyyyMMddHHmmss");
            inBlock.Tables[0].Rows[0]["PROPOSER"] = USERID;
            inBlock.Tables[0].Rows[0]["APPLY_TIME"] = APPLY_TIME + DateTime.Now.ToString("HHmmss");
            inBlock.Tables[0].Rows[0]["REMARK"] = REMARK;


            sql_temp = " select STOCK_NO,b.stock_char from  tsimm01 b  "
                        + " where b.stock_no = '" + table_rec_out.Rows[0]["STOCK_NO"].ToString() + "'    "
                   ;

            EI.EIInfo inBlock_temp = EF.Utility.ExecQuery(sql_temp);


            inBlock.Tables[0].Rows[0]["NEW_STOCK_NO"] = inBlock_temp.Tables[0].Rows[0]["STOCK_NO"];
            inBlock.Tables[0].Rows[0]["STOCK_CHAR_END"] = inBlock_temp.Tables[0].Rows[0]["STOCK_CHAR"];
            inBlock.Tables[0].Rows[0]["NEW_STOCK_NO"] = table_rec_out.Rows[0]["STOCK_NO"].ToString();

            inBlock.Tables[0].Rows[0]["AUDIT_OPINION"] = "YM06SR";

            





            //- 52 总件数
            // - 52.000000  总重量
            //REC_CREATOR 06327   记录创建者
            // 20231116144619  申请时刻
            // 20231116144717  记录创建时刻

            //  N5  接收仓库属性
            //    NC5 新库号 
            //MOVE_STOCK_NO   RN23B00675 移库单号
            //SR  移库类型
            //改判成轧球 备注




            double mat_wt = 0, mat_num = 0;
            for (int i = 0; i < table_rec_out.Rows.Count; i++)
            {
                mat_num = mat_num + 1;
                mat_wt = mat_wt + double.Parse(table_rec_out.Rows[i]["MAT_WT"].ToString());
            }

            inBlock.Tables[0].Rows[0]["TOTAL_NUM"] = mat_num;
            inBlock.Tables[0].Rows[0]["TOTAL_WT"] = mat_wt;
          


            inBlock.Tables.Add("TMM0033");
             
            //出库标签【未合并的】
            inBlock.Tables["TMM0033"].Merge(table_rec_out); 
              
            inBlock.sys_info.company_code = "LT";
            inBlock.sys_info.company_name = "常熟市龙腾特种钢有限公司";

            inBlock.sys_info.userid     = USERID;
            inBlock.sys_info.username   = USERNAME;
            inBlock.sys_info.formname   = FORMNAME;






            // 调用后台services保存信息
            EI.EIInfo  outBlock2 = EI.EITuxedo.CallService("mm0034_save", inBlock);
            if (outBlock2.sys_info.flag != 0)
            {
                outBlock.Tables["SYS"].Rows.Add(outBlock2.sys_info.flag, outBlock2.sys_info.msg);
                return outBlock;
            }
            else
            {
                outBlock2.Tables[0].TableName = "Table0";
                outBlock.Tables.Add(outBlock2.Tables[0].Copy()); 
                outBlock.Tables["SYS"].Rows.Add(outBlock.sys_info.flag, "生产退库成功[" + outBlock2.DataSet.Tables[0].Rows[0]["MOVE_STOCK_NO"].ToString() + "]");
                return outBlock;
            }
            

        }


        //销售出库确认PA31(19->31);确认回退PB31（31->19);DEL
        [HttpPost]
        [Route("PostYm06sr_pro")]
        public System.Data.DataSet PostYm06sr_pro([FromBody]  JObject obj)
        {

            //系统信息；
            EI.EIInfo outBlock = new EI.EIInfo();
            outBlock.Tables.Add("SYS");
            outBlock.Tables["SYS"].Columns.Add("FLAG");
            outBlock.Tables["SYS"].Columns.Add("MSG");




            string out_stock_no = obj["OUT_STOCK_NO"]   == null ? ""    : obj["OUT_STOCK_NO"].ToString();
            string pro_type     = obj["PRO_TYPE"]       == null ? " "   : obj["PRO_TYPE"].ToString();






            string USERID   = obj["USERID"] == null ? " " : obj["USERID"].ToString();
            string USERNAME = obj["USERNAME"] == null ? " " : obj["USERNAME"].ToString();
            string FORMNAME = obj["FORMNAME"] == null ? " " : obj["FORMNAME"].ToString();




            EI.EIInfo inblock = new EI.EIInfo();


            inblock.Tables[0].Columns.Add("IOSTOCK_BILL_NO");
            inblock.Tables[0].Columns.Add("OUT_STOCK_NO");
            inblock.Tables[0].Columns.Add("MOVE_STOCK_NO");

            

            inblock.Tables[0].Rows.Add(out_stock_no, out_stock_no, out_stock_no);





            inblock.sys_info.company_code = "LT";
            inblock.sys_info.company_name = "常熟市龙腾特种钢有限公司";

            inblock.sys_info.userid = USERID;
            inblock.sys_info.username = USERNAME;
            inblock.sys_info.formname = FORMNAME;


            //
            inblock.Tables[0].TableName = pro_type;

            string svr = "pmmm02n_pro";

            if (pro_type.ToUpper() == "DEL") //
            {
                svr = "mm0034_del";
            }


            // 调用后台services保存信息 //调拨出库；
            EI.EIInfo outBlock2 = EI.EITuxedo.CallService(svr, inblock);
            if (outBlock2.sys_info.flag != 0)
            {
                outBlock.Tables["SYS"].Rows.Add(outBlock2.sys_info.flag, outBlock2.sys_info.msg);
                return outBlock;
            }
            else
            {
                outBlock.Tables["SYS"].Rows.Add(outBlock2.sys_info.flag, outBlock2.sys_info.msg);
                return outBlock;
            }


        }








        
 

    }
}